home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / server_1.zip / _VOTE.QC < prev    next >
Text File  |  1996-10-04  |  10KB  |  329 lines

  1. /*
  2. **
  3. ** _vote.qc (Vote Code, 1.1)
  4. **
  5. ** Copyright (C) 1996 Johannes Plass
  6. ** 
  7. ** This program is free software; you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation; either version 2 of the License, or
  10. ** (at your option) any later version.
  11. ** 
  12. ** This program is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with this program; if not, write to the Free Software
  19. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ** 
  21. ** Author:   Johannes Plass (plass@dipmza.physik.uni-mainz.de)
  22. **
  23. */
  24.  
  25. void(entity player) VoteInfo =
  26. {
  27.    if (!USE_MODULE_VOTE) return;
  28.  
  29.                // 123456789#123456789#123456789#12345678
  30.    sprint(player,"£");
  31.    sprint(player," Vote");
  32.    sprint(player,      " allows to vote. Type\n");
  33.    sprint(player,"  'help-vote' for help.\n");
  34. };
  35.  
  36. void(entity player) VoteInit =
  37. {
  38.    if (!USE_MODULE_VOTE) return;
  39.  
  40.    stuffcmd(player,"alias help-vote \"impulse 211\";\n");
  41.    stuffcmd(player,"alias votes \"impulse 212\";\n");
  42.    if (USE_SUBMODULE_VOTE_EXIT) {
  43.       stuffcmd(player,"alias vote-exit \"impulse 213\";\n");
  44.    }
  45.    if (USE_SUBMODULE_VOTE_EXITRULES) {                    //#jp#(ExitRules)
  46.       stuffcmd(player,"alias vote-exitrules \"impulse 214\";\n");    //#jp#(ExitRules)
  47.    }                                    //#jp#(ExitRules)
  48. };
  49.  
  50. void(entity player) VoteActiveMessage =
  51. {
  52.    if (!USE_MODULE_VOTE) return;
  53.                // 123456789#123456789#123456789#12345678
  54.    sprint(player,"  Vote          (help-vote)\n");
  55. };
  56.  
  57. void(entity player) VoteHelp =
  58. {
  59.    if (!USE_MODULE_VOTE) return;
  60.  
  61.                // 123456789#123456789#123456789#12345678
  62.    sprint(player,"Vote:");
  63.    sprint(player,      " vote via one of the commands\n");
  64.    VoteExitHelp(player);
  65.    VoteExitRulesHelp(player); //#jp#(ExitRules)
  66.    sprint(player,"The command 'votes' shows current\n");
  67.    sprint(player,"voting statistics.\n");
  68. };
  69.  
  70. void(entity player) VoteShowVotes =
  71. {
  72.    local float num2,req_votes;
  73.    local string numstr;
  74.  
  75.    //dprint("VoteShowVotes: executing\n");
  76.  
  77.    if (!USE_MODULE_VOTE) return;
  78.  
  79.    VoteCheckVotes();
  80.  
  81.    req_votes = 0;
  82.    if (!vote_level_has_exit && exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
  83.       req_votes = 1;
  84.    } else {
  85.       num2 = vote_voters;
  86.       while (num2 > 0) { req_votes = req_votes + 1; num2 = num2 - 2; }
  87.    }
  88.  
  89.                // 123456789#123456789#123456789#12345678
  90.    sprint(player,"Statistics for ");
  91.    numstr = ftos(vote_voters);
  92.    sprint(player,numstr);
  93.    if (vote_voters != 1) sprint(player," voters:\n");
  94.    else                  sprint(player," voter:\n");
  95.    if (USE_SUBMODULE_VOTE_EXITRULES) {            //#jp#(ExitRules)
  96.       sprint(player,"  vote-exitrules: ");        //#jp#(ExitRules)
  97.       if (exitrules_status == EXITRULES_STATUS_TIGHT) {    //#jp#(ExitRules)
  98.          numstr = ftos(vote_pro_exitrules);        //#jp#(ExitRules)
  99.          sprint(player,numstr);                //#jp#(ExitRules)
  100.          sprint(player," (");                //#jp#(ExitRules)
  101.          numstr = ftos(req_votes);            //#jp#(ExitRules)
  102.          sprint(player,numstr);                //#jp#(ExitRules)
  103.          sprint(player," required)");            //#jp#(ExitRules)
  104.          sprint(player,"\n");                //#jp#(ExitRules)
  105.       } else {                        //#jp#(ExitRules)
  106.          sprint(player,"exiting is allowed\n");        //#jp#(ExitRules)    
  107.       }                            //#jp#(ExitRules)
  108.    }                            //#jp#(ExitRules)
  109.    if (USE_SUBMODULE_VOTE_EXIT) {
  110.       sprint(player,"  vote-exit:      ");
  111.       if (vote_exit_status & VOTE_EXIT_ENABLED) {
  112.          numstr = ftos(vote_pro_exit);
  113.          sprint(player,numstr);
  114.          sprint(player," (");
  115.          numstr = ftos(req_votes);
  116.          sprint(player,numstr);
  117.          sprint(player," required)");
  118.          sprint(player,"\n");
  119.       } else {
  120.          sprint(player,"disabled\n");    
  121.       }
  122.    }
  123. };
  124.  
  125. float() VoteThink =
  126. {
  127.  
  128.    //dprint("VoteThink: executing\n");
  129.  
  130.    if (!USE_MODULE_VOTE) {
  131.       vote_checktime = vote_checktime + 500000;
  132.       return;
  133.    }
  134.    if (!vote_checktime) {
  135.       // don't allow voting for exiting on start level
  136.       if (world.model == "maps/start.bsp") vote_exit_status = VOTE_EXIT_DISABLED;
  137.       else                                 vote_exit_status = VOTE_EXIT_ENABLED;
  138.       vote_level_has_exit = 1;
  139.       if      (world.model == "maps/end.bsp") vote_level_has_exit = 0;
  140.       else if (world.model == "maps/dm1.bsp") vote_level_has_exit = 0;
  141.       else if (world.model == "maps/dm2.bsp") vote_level_has_exit = 0;
  142.       else if (world.model == "maps/dm3.bsp") vote_level_has_exit = 0;
  143.       else if (world.model == "maps/dm4.bsp") vote_level_has_exit = 0;
  144.       else if (world.model == "maps/dm5.bsp") vote_level_has_exit = 0;
  145.       else if (world.model == "maps/dm6.bsp") vote_level_has_exit = 0;
  146.       vote_checktime = time + 40;
  147.       return;
  148.    }
  149.    if (time < 60) return; // make sure all player are in the level
  150.  
  151.    vote_checktime = time + 10;
  152.  
  153.    VoteCheckVotes();
  154.  
  155.    if (!vote_level_has_exit) {
  156.       if (exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
  157.          if (!vote_exit_announced) {
  158.                  // 123456789#123456789#123456789#12345678
  159.             bprint("Vote:");
  160.             bprint(     " a single vote suffices to exit\n");
  161.             bprint("the level now.\n");
  162.             vote_exit_announced = 1;
  163.          }
  164.          if (vote_voters && vote_pro_exit) {
  165.             VoteExitExit();
  166.             return;
  167.          }
  168.          if (vote_voters && vote_pro_exitrules) {
  169.             VoteExitRulesDisable();
  170.             return;
  171.          }
  172.       }
  173.    }
  174.  
  175.    if (vote_voters && vote_pro_exit) {
  176.       if (vote_pro_exit >= vote_voters * 0.5) {
  177.          VoteExitExit();
  178.          return;
  179.       }
  180.    }
  181.  
  182.    if (   vote_voters && vote_pro_exitrules        //#jp#(ExitRules)
  183.        && (vote_pro_exitrules >= vote_voters * 0.5)) {    //#jp#(ExitRules)
  184.       VoteExitRulesDisable();                //#jp#(ExitRules)
  185.    }                            //#jp#(ExitRules)
  186. };
  187.  
  188. void() VoteCheckVotes =
  189. {
  190.    local entity e;
  191.  
  192.    //dprint("VoteCheckVotes: executing\n");
  193.  
  194.    vote_voters = vote_pro_exitrules = vote_pro_exit = 0;
  195.    e = find(world, classname, "player");
  196.    while (e != world) {
  197.       if (!PlayerStatusPlayerIsBogusPlayer(e)) {
  198.          vote_pro_exitrules = vote_pro_exitrules + e.vote_exitrules;
  199.          vote_pro_exit      = vote_pro_exit      + e.vote_exit;
  200.          vote_voters        = vote_voters + 1;
  201.       }
  202.       e = find(e, classname, "player");
  203.    }
  204. };
  205.  
  206. /*
  207. ===============================================================
  208.     Voting for exiting immediately
  209. ===============================================================
  210. */
  211.  
  212. void(entity player) VoteExitHelp =
  213. {
  214.    local string f;
  215.    if (!USE_MODULE_VOTE) return;
  216.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  217.                // 123456789#123456789#123456789#12345678
  218.    sprint(player,"  vote-exit: the majority may decide\n");
  219.    sprint(player,"     to exit the level immediately.\n" );
  220.    sprint(player,"     Onls without exit a single\n");
  221.    sprint(player,"     vote suffices to exit\n" );
  222.    sprint(player,"     once "                            );
  223.    f = ftos(EXITRULES_FRAGLIMIT);
  224.    sprint(player,            f                           );
  225.    sprint(player,            " frags are reached.\n"     );
  226. };
  227.  
  228. void(entity player) VoteExitVote =
  229. {
  230.    if (!USE_MODULE_VOTE) return;
  231.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  232.  
  233.    if (vote_exit_status & VOTE_EXIT_DISABLED) {
  234.                   // 123456789#123456789#123456789#12345678
  235.       sprint(player,"Voting for exiting is not possible\non this level.\n");
  236.       return;
  237.    }
  238.  
  239.    if (player.vote_exit) {
  240.       player.vote_exit = 0;
  241.       sprint(player,"Vote against exiting accepted\n");
  242.    } else {
  243.       player.vote_exit = 1;
  244.       sprint(player,"Vote for exiting accepted\n");
  245.    }
  246.    vote_checktime = -100;
  247. };
  248.  
  249. void() VoteExitExit =
  250. {
  251.    local float f;
  252.  
  253.    if (!USE_MODULE_VOTE) return;
  254.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  255.  
  256.    f = 0;
  257.    if (!vote_level_has_exit) {
  258.       if (exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
  259.          if (vote_pro_exit) {
  260.             f = 1;
  261.             bprint ("A player decided to exit.\n");
  262.             if (USE_MODULE_SERVERCONSOLE) {        //#jp#(ServerConsole)
  263.                dprint ("A player decided to exit.\n");    //#jp#(ServerConsole)
  264.             }                        //#jp#(ServerConsole)
  265.          }
  266.       }
  267.    }
  268.  
  269.    if (!f) {
  270.       bprint ("The majority decided to exit.\n");
  271.       if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  272.          dprint ("The majority decided to exit.\n");    //#jp#(ServerConsole)
  273.       }                            //#jp#(ServerConsole)
  274.    }
  275.  
  276.    NextLevel();
  277. };
  278.  
  279. /*
  280. ===============================================================
  281.     Voting for disabling ExitRules
  282.     //#jp#(ExitRules)
  283. ===============================================================
  284. */
  285.  
  286. void(entity player) VoteExitRulesHelp =
  287. {
  288.    if (!USE_MODULE_VOTE) return;
  289.    if (!USE_MODULE_EXITRULES) return;
  290.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  291.                // 123456789#123456789#123456789#12345678
  292.    sprint(player,"  vote-exitrules: the majority may \n");
  293.    sprint(player,"     disable the current ExitRules.\n");
  294. };
  295.  
  296. void(entity player) VoteExitRulesVote =
  297. {
  298.    if (!USE_MODULE_VOTE) return;
  299.    if (!USE_MODULE_EXITRULES) return;
  300.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  301.  
  302.    if (exitrules_status != EXITRULES_STATUS_TIGHT) {
  303.                   // 123456789#123456789#123456789#12345678
  304.       sprint(player,"ExitRules are disbled on this level,\nvoting is not necessary.\n");
  305.       return;
  306.    }
  307.                // 123456789#123456789#123456789#12345678
  308.    sprint(player,"Vote for disabling ExitRules accepted\n");
  309.    player.vote_exitrules = 1;
  310.    vote_checktime = -100;
  311. };
  312.  
  313. void() VoteExitRulesDisable =
  314. {
  315.    //dprint("VoteExitRulesDisable: executing\n");
  316.    if (!USE_MODULE_VOTE) return;
  317.    if (!USE_MODULE_EXITRULES) return;
  318.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  319.    if (exitrules_status != EXITRULES_STATUS_TIGHT) return;
  320.  
  321.          // 123456789#123456789#123456789#12345678
  322.    bprint ("The majority disbled ExitRules, you\nmay exit at any time.\n");
  323.    if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  324.       dprint ("The majority disabled ExitRules.\n");    //#jp#(ServerConsole)
  325.    }                            //#jp#(ServerConsole)
  326.    exitrules_status = EXITRULES_STATUS_SOFT;
  327. };
  328.  
  329.